/*alu control 根据aluop和aluop生成alucontrol码*/
module AluControl (
    alu_op,
    fun,
    alu_ctr
);

    input [3:0]alu_op;
    input [5:0] fun;
    output reg [3:0] alu_ctr;
    //function码
    parameter   ADD   = 6'b100000;                  
    parameter   ADDU  = 6'b100001;                  
    parameter   SUB   = 6'b100010;                  
    parameter   SLT   = 6'b101010;                  
    parameter   AND   = 6'b100100;                  
    parameter   OR    = 6'b100101;                  
    parameter   XOR   = 6'b100110;                  
    parameter   SL_ALUOP = 4'b0000, BR_ALUOP = 4'b0001, AL_ALUOP = 4'b0010, LU_ALUOP = 4'b0011,ADDI_ALUOP=4'b0100,ORI_ALUOP=4'b0101;

    parameter   AND_ALU = 4'b0000, OR_ALU = 4'b0001, ADD_ALU = 4'b0010, SUB_ALU = 4'b0011, SLT_ALU = 4'b0100, XOR_ALU = 4'b0101, LUI_ALU = 4'b0110;
    
    always @(*) begin
        case(alu_op)
            SL_ALUOP: alu_ctr = ADD_ALU;
            BR_ALUOP: alu_ctr = SUB_ALU;
            LU_ALUOP: alu_ctr = LUI_ALU;
            AL_ALUOP:
            begin
                case(fun)
                    ADD: alu_ctr = ADD_ALU;  
                    ADDU: alu_ctr = ADD_ALU;  
                    SUB: alu_ctr = SUB_ALU;  
                    AND: alu_ctr = AND_ALU;  
                    OR: alu_ctr = OR_ALU;   
                    XOR: alu_ctr = XOR_ALU;  
                    SLT: alu_ctr = SLT_ALU;  
                endcase
            end
            ADDI_ALUOP:alu_ctr=ADD_ALU;
            ORI_ALUOP:alu_ctr=OR_ALU;
            default:
                alu_ctr = 4'bxxxx;
           
        endcase
    end
endmodule //alu_ctr